using System.Reflection;
using DotNetNuke.Modules.Announcements;
using DotNetNuke.Entities.Users;

namespace MetaPostProvider.Announcements
{
    public partial class ControllerFactory
    {
        public static AnnouncementsController_Proxy CreateController(int portalId, int moduleId)
        {
            AnnouncementsController_Proxy controller = null;
            ModuleVersion current = new ModuleVersion(portalId, new ITCrossing.metaPostAnnouncementsProvider().ModuleDefFriendlyString);
            if (current.IsVersionEqualOrNewerThan("03.03.05"))
                if (current.IsVersionEqualOrNewerThan("03.04.00"))
                    controller = new AnnouncementsController_4_0_0(moduleId);
                else
                    controller = new AnnouncementsController_3_3_5();
            else
                throw new ITCrossing.MetaPostException("SupportedVersions", "This provider only supports Announcements modules after 03.03.05");
            return controller;
        }

        public abstract class AnnouncementsController_Proxy : AnnouncementsController
        {
            private MethodInfo _Delete = null;
            protected MethodInfo _Add = null; // protected for the _4_0_0 version...

            protected internal AnnouncementsController_Proxy()
            {
                _Delete = base.GetType().GetMethod("DeleteAnnouncement");
                _Add = DataProvider.Instance().GetType().GetMethod("AddAnnouncement");
            }

            protected MethodInfo DeleteProxy
            {get{return _Delete;}}

            protected MethodInfo AddProxy
            {get{return _Add;}}

            public abstract void Delete(int ItemID);
            public abstract int Add(AnnouncementInfo objAnnouncement);
        }
    }
}
